﻿using PMSystem.ApplicationLogics;
using PMSystem.DataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PMSytem.Windows.App
{
    public class CurrentContext
    {
        public User CurrentUser { get; private set; }
    }

    public static class LoginUser
    {
        private static User _user;
        public static User CurrentUser
        {
            get { return _user; }
            set { 
                _user = value;
                LoadCurrentUserRoles();
            }
        }

        private static List<UserRole> _userRoles;
        public static List<UserRole> CurrentUserRoles
        {
            get { 
               
                return _userRoles; 
            }
            set { _userRoles = value; }
        }



        public static void LoadCurrentUserRoles()
        {
            if (CurrentUser != null)
                CurrentUserRoles = new UserService().GetUserRoles(CurrentUser.UserId);
        }
        public static bool IsUserHasEditPermission { 
            get
            {
                if (CurrentUserRoles.Any(x => x.RoleId == (int)UserRoles.Administrator || x.RoleId == (int)UserRoles.Operator))
                    return true;
                return false;
            }
        }

        public static bool IsAdminUser
        {
            get
            {
                if (CurrentUserRoles.Any(x => x.RoleId == (int)UserRoles.Administrator))
                    return true;
                return false;
            }
        }
         public static bool IsOperatorUser
        {
            get
            {
                if (CurrentUserRoles.Any(x => x.RoleId == (int)UserRoles.Operator))
                    return true;
                return false;
            }
        }
         public static bool IsNormalUser
         {
             get
             {
                 if (CurrentUserRoles.Any(x => x.RoleId == (int)UserRoles.User))
                     return true;
                 return false;
             }
         }
    }

    public enum UserRoles
    {
        Administrator=1,
        Operator=2,
        User=3
    }
}
